<?php
// +----------------------------------------------------------------------
// Csmmeet [ Csmonline ]
// Author: chensm <chenshiming0802@163.com>
// Create by chensm at 2020-03-31
// +----------------------------------------------------------------------
namespace app\admin\controller\csmonline;

use addons\csmonline\library\CsmBackend;

/**
 * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmonline/chartchinaregister/index
 */
class Chartchinaregister extends CsmBackend
{

    /**
     */
    protected $model = null;

    public function index()
    {
        //1.0.2 修复了HTTPS无法打开地图的问题@chensm
        //header("Content-Security-Policy: upgrade-insecure-requests");
        $begin = $this->csmreq("begin", true);
        $end = $this->csmreq("end", true);

        $dao = new \app\admin\model\csmonline\Pieregion();
        $dataList = $dao->where("statdate", ">=", $begin)
            ->where("statdate", "<=", $end)
            ->where("country", "=", "中国")
            ->group("province")
            ->field("province name,sum(newregisteredus) value")
            ->select();
        $datalist2 = $dao->where("statdate", ">=", $begin)
            ->where("statdate", "<=", $end)
            ->where("country", "<>", "中国")
            ->field("province name,sum(newregisteredus) value")
            ->group("province")
            ->select();

        $total = $dao->where("statdate", ">=", $begin)
            ->where("statdate", "<=", $end)
            ->sum("newregisteredus");

        $this->view->assign('dataList', $dataList);
        $this->view->assign('dataList2', $datalist2);
        $this->view->assign('total', $total);

        $chartconfig = [
            [
                "gt" => 1000,
                "label" => "> 1000 人",
                "color" => "#7f1100"
            ],
            [
                "gte" => 100,
                "lte" => 1000,
                "label" => "100 - 1000 人",
                "color" => "#ff5428"
            ],
            [
                "gte" => 10,
                "lte" => 99,
                "label" => "10 - 99 人",
                "color" => "#ff8c71"
            ],
            [
                "gte" => 1,
                "lte" => 9,
                "label" => "1 - 9 人",
                "color" => "#ffd768"
            ],
            [
                "value" => 0,
                "label" => "0人",
                "color" => "#f4f4f4"
            ]
        ];
        $this->view->assign('chartconfig', $chartconfig);

        return $this->view->fetch();
    }
}

